package com.lwj.liwanjia.view.activity.myindent;


import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.lwj.liwanjia.MainActivity;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.VpAdapter;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.view.fragment.myindent.AllIndentFragment;
import com.lwj.liwanjia.view.fragment.myindent.CompleteFragment;
import com.lwj.liwanjia.view.fragment.myindent.OrderFragment;
import com.lwj.liwanjia.view.fragment.myindent.UnOrderFragment;
import com.lwj.liwanjia.view.fragment.myindent.UnPaidFragment;
import com.lwj.liwanjia.view.fragment.myindent.UnTakeFragment;
import com.lwj.liwanjia.view.fragment.shouye.PromotionFragment;
import com.lwj.liwanjia.view.fragment.supermarket.MiaoShuFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyIndentActivity extends BaseActivity {

    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;


    private String[] tabs = {"全部", "待付款", "待接单", "已接单", "待收货", "已完成"};
    private List<Fragment> fragmentList = new ArrayList<>();
    private VpAdapter vpAdapter;
    private String type;

    @Override
    protected void initView() {
        type = getIntent().getStringExtra("type");
        tvLeft.setVisibility(View.VISIBLE);
        tvTitle.setText("我的订单");
        getFragments();
        vpAdapter = new VpAdapter(getSupportFragmentManager(), tabs, fragmentList);
        viewPager.setAdapter(vpAdapter);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setOffscreenPageLimit(6);
        if (type.equals("0") || type.equals("-1")) {
            viewPager.setCurrentItem(0);
        } else if (type.equals("1")) {
            viewPager.setCurrentItem(1);
        } else if (type.equals("4")) {
            viewPager.setCurrentItem(4);
        } else if (type.equals("5")) {
            viewPager.setCurrentItem(5);
        }
    }

    private void getFragments() {
        fragmentList.add(new AllIndentFragment());
        fragmentList.add(new UnPaidFragment());
        fragmentList.add(new UnOrderFragment());
        fragmentList.add(new OrderFragment());
        fragmentList.add(new UnTakeFragment());
        fragmentList.add(new CompleteFragment());
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_indent;
    }

    @OnClick(R.id.tv_left)
    public void onViewClicked() {
        if (type.equals("-1")) {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        }
        finish();
    }

    @Override
    public void onBackPressed() {
        if (type.equals("-1")) {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        }
        finish();
    }
}
